package com.frxuexi.park2210.news

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.mvvm.BaseActivity
import com.frxuexi.lib_base.net.Const
import com.frxuexi.park2210.R
import com.frxuexi.park2210.databinding.ActivityNewsAddBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/NewsAddActivity")
@AndroidEntryPoint
class NewsAddActivity : BaseActivity<ActivityNewsAddBinding,NewsViewModel>() {
    override fun initData() {
        vm.addNewsSuc.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }

    override fun initView() {
        binding.headerNews.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.setText("添加文化")
        }

        binding.btnAddNews.setOnClickListener {
            val map = mutableMapOf<String, Any>()
            map["newsTime"]=vm.getDateTime(System.currentTimeMillis())
            map["newsTitle"]=binding.etNewsTitle.text.toString()
            map["newsValue"]=binding.etNewsValue.text.toString()
            map["userId"]=SPUtils.getInstance().getInt(Const.UID)
            vm.addNews(map)
        }
    }

}